<?php
namespace App\Http\Service;

use App\Models\HonestassetAnnouncement;

class HonestassetAnnounceService{

    public static function getAnnouncementListPageInit($pageSize=DEFAULT_PAGESIZE,$where=[] , $searchVal=null){
        $announceEntity=HonestassetAnnouncement::where($where)
            ->orderby('sort','DESC')
            ->orderby('id','DESC');
        if(!empty($searchVal)){
            return $announceEntity->where('name','like','%'.$searchVal.'%')
                ->paginate($pageSize);
        }
        return $announceEntity->paginate($pageSize);
    }

    public static function getAnnounceTypeList(){
        return HonestassetAnnouncement::getAnnounceTypeList();
    }

    public static function createOneAnnounce($announceInfo){
        return HonestassetAnnouncement::create($announceInfo);
    }

    public static function getOneAnnounce($announceId){
        return HonestassetAnnouncement::find($announceId);
    }

    public static function updateOneAnnounce($announceData){
        return HonestassetAnnouncement::find($announceData['id'])
                        ->update($announceData);
    }

    public static function deleteOneAnnounce($announceId){
        return HonestassetAnnouncement::find($announceId)
                    ->update(['isdelete'=>1]);
    }

}